package edu.lingnan.common;

import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class Result {
    /** 返回实体 */
    private Object data;
    /** 返回状态码 */
    private Integer code;
    /** 返回消息 */
    private String msg;
    /** 是否成功 */
    private Boolean success;
    /** 总条数 */
    private Integer total;
    /** 当前页 */
    private Integer current;
    /** 总页数 */
    private Integer pages;
    /** 每页条数 */
    private Integer size;

    /** 成功状态码 */
    public static final Integer SUCCESS_CODE = 200;
    /** 失败状态码 */
    public static final Integer ERROR_CODE = 201;

    public Result(Object data) {
        this.data = data;
        this.code = 200;
        this.msg = "success";
        this.success = true;
    }

    public Result(Object data, Integer code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
        this.success = true;
    }

    public Result(Object data, Integer code, String msg, Boolean success) {
        this.data = data;
        this.code = code;
        this.msg = msg;
        this.success = success;
    }

    public Result(Object data, Integer code, String msg, Boolean success, Integer total, Integer current, Integer pages, Integer size) {
        this.data = data;
        this.code = code;
        this.msg = msg;
        this.success = success;
        this.total = total;
        this.current = current;
        this.pages = pages;
        this.size = size;
    }

    public static Result success(Object data) {
        return new Result(data);
    }

    public static Result success(Object data, Integer code, String msg) {
        return new Result(data, code, msg);
    }

    public static Result success(Object data, Integer code, String msg, Boolean success) {
        return new Result(data, code, msg, success);
    }

    public static Result success(Object data, Integer code, String msg, Boolean success, Integer total, Integer current, Integer pages, Integer size) {
        return new Result(data, code, msg, success, total, current, pages, size);
    }

    public static Result error(Integer code, String msg) {
        return new Result(null, code, msg);
    }

    public static Result error(Integer code, String msg, Boolean success) {
        return new Result(null, code, msg, success);
    }

    public static Result error(Integer code, String msg, Boolean success, Integer total, Integer current, Integer pages, Integer size) {
        return new Result(null, code, msg, success, total, current, pages, size);
    }

    public static Result fail(String msg) {
        return new Result(null, 500, msg);
    }
}
